package co.fitstart.entity.finance;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.Constant;
import co.fitstart.entity.order.Order;

/**
 * 
 * @author dan
 *
 */
@Entity
@Table(name = "receivables")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class Receivables {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 发票日期 */
    private Date date;
    
    /** 销售类型编号 */
    private String saleNumber;
    
    /** 部门编码 */
    private String siteCode;
    
    /** 业务员编码 */
    private String salesmanCode;
    
    /** 订单号 */
    private String orderCode;
    
    /** 门店id */
    private Long siteId;
    
    /** 制单人 */
    private String manager;
    
    /** 发货单号 */
    private String shippingNumber;
    
    /** 联系人 */
    private String userName;
    
    /** 联系人编码 */
    private String userCode;
    
    /** 存货编码 */
    private String productCode;
    
    /** 主计量数量 */
    private String amount;
    
    /** 原价 */
    private BigDecimal originalPrice;
    
    /** 付款价格 */
    private BigDecimal price;
    
    private boolean export;
    
    public Receivables() {
        
    }
    
    public Receivables(Order order, int price) {
        this.date = new Date();
        this.saleNumber = order.getOrderType().isOnline() ? "1" : order.getOrderType().isOffline() ?  order.getCourse().isExperience() ? "23" : order.getCourse().isYear() ? "22" : "21" : "3";
        this.siteCode = order.getOrderType().isOffline() ? order.getSite().getFinanceCode() : order.getOrderType().isOnline() ? "H06" : "H02";
        this.salesmanCode = order.getOrderType().isOffline() ? order.getSalesman() != null ? order.getSalesman().getFinanceCode() : "" : order.getOrderType().isOnline() ? "017" : "054";
        this.orderCode = order.getCode();
        this.siteId = order.getOrderType().isOffline() ? order.getSite().getId() : null;
        this.manager = order.getOrderType().isOffline() ? "" : "JIM";
        this.shippingNumber = order.getAttrs().get(Constant.SHIPPING_EXPRESSAGE_NUMBER) != null ? order.getAttrs().get(Constant.SHIPPING_EXPRESSAGE_NUMBER).getValue() : "";
        this.userName = order.getStudent().getName();
        this.userCode = "RMJU0" + order.getUser().getId();
        this.productCode = order.getProduct().getProductCode();
        this.amount = order.getOrderType().isOthers() ? "1" : String.valueOf(order.getCourse().getHours());
        this.originalPrice = new BigDecimal(order.getPrice()).divide(new BigDecimal(100));
        this.price = new BigDecimal(price).divide(new BigDecimal(100));
        this.export = false;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }

    /**
     * @return the saleNumber
     */
    public String getSaleNumber() {
        return saleNumber;
    }

    /**
     * @return the siteCode
     */
    public String getSiteCode() {
        return siteCode;
    }

    /**
     * @return the salesmanCode
     */
    public String getSalesmanCode() {
        return salesmanCode;
    }

    /**
     * @return the orderCode
     */
    public String getOrderCode() {
        return orderCode;
    }

    /**
     * @return the siteId
     */
    public Long getSiteId() {
        return siteId;
    }

    /**
     * @return the manager
     */
    public String getManager() {
        return manager;
    }

    /**
     * @return the shippingNumber
     */
    public String getShippingNumber() {
        return shippingNumber;
    }

    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * @return the userCode
     */
    public String getUserCode() {
        return userCode;
    }

    /**
     * @return the productCode
     */
    public String getProductCode() {
        return productCode;
    }

    /**
     * @return the amount
     */
    public String getAmount() {
        return amount;
    }

    /**
     * @return the originalPrice
     */
    public BigDecimal getOriginalPrice() {
        return originalPrice;
    }

    /**
     * @return the price
     */
    public BigDecimal getPrice() {
        return price;
    }

    /**
     * @return the export
     */
    public boolean isExport() {
        return export;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    /**
     * @param saleNumber the saleNumber to set
     */
    public void setSaleNumber(String saleNumber) {
        this.saleNumber = saleNumber;
    }

    /**
     * @param siteCode the siteCode to set
     */
    public void setSiteCode(String siteCode) {
        this.siteCode = siteCode;
    }

    /**
     * @param salesmanCode the salesmanCode to set
     */
    public void setSalesmanCode(String salesmanCode) {
        this.salesmanCode = salesmanCode;
    }

    /**
     * @param orderCode the orderCode to set
     */
    public void setOrderCode(String orderCode) {
        this.orderCode = orderCode;
    }

    /**
     * @param siteId the siteId to set
     */
    public void setSiteId(Long siteId) {
        this.siteId = siteId;
    }

    /**
     * @param manager the manager to set
     */
    public void setManager(String manager) {
        this.manager = manager;
    }

    /**
     * @param shippingNumber the shippingNumber to set
     */
    public void setShippingNumber(String shippingNumber) {
        this.shippingNumber = shippingNumber;
    }

    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * @param userCode the userCode to set
     */
    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    /**
     * @param productCode the productCode to set
     */
    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(String amount) {
        this.amount = amount;
    }

    /**
     * @param originalPrice the originalPrice to set
     */
    public void setOriginalPrice(BigDecimal originalPrice) {
        this.originalPrice = originalPrice;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    /**
     * @param export the export to set
     */
    public void setExport(boolean export) {
        this.export = export;
    }

}
